package main

import (
	"bsfswagger/base"
	"bsfswagger/go_api"
	"bsfswagger/java_api"
	"bsfswagger/swagger2"
	"github.com/tidwall/gjson"
)

type SwaggerParser struct {
}

func (m *SwaggerParser) Parser(bs []byte) *base.Api {
	json := string(bs)
	version := gjson.Get(json, "swagger").String()
	if version == "2.0" {
		return (&swagger2.Swagger2Parser{}).ParserSwagger(json)
	}
	return nil
}

func (m *SwaggerParser) Template(pkg string, language string, outDir string, api *base.Api, replaceTypeNames []string) {
	if language == "go" {
		tmpl := &go_api.GoTemplate{Pkg: pkg, OutDir: outDir, Api: api, ReplaceTypeNames: replaceTypeNames}
		tmpl.Render()
	} else if language == "java" {
		tmpl := &java_api.JavaTemplate{Pkg: pkg, OutDir: outDir, Api: api, ReplaceTypeNames: replaceTypeNames}
		tmpl.Render()
	} else {
		panic("language not support:" + language)
	}
}
